import shutil
import traceback

from django.conf import settings
from django.http import JsonResponse

from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import api_view

from XApiTestServer.models import *
from XApiTestServer.utils.test_stat import *
from XApiTestServer.utils.response import *
import logging


logger = logging.getLogger('XApiTestServer')

@api_view(('GET',))
def dashboard_stat(request):
    """
    Show HomePage after login system.
    :param request:
    :return:
    """
    project_total = ProjectInfo.objects.count()
    module_total = ModuleInfo.objects.count()
    case_total = TestCase.objects.count()
    suite_total = TestSuite.objects.count()

    total = get_total_values()
    manage_info = {
        'project_total': project_total,
        'module_total': module_total,
        'case_total': case_total,
        'suite_total': suite_total,
        # 'account': request.session["now_account"],
        'total': total
    }

    response_body = SUCCESS_LIST
    response_body['results'] = manage_info

    # init_filter_session(request)
    return JsonResponse(response_body, status=status.HTTP_200_OK)
